package licode;

import java.util.Stack;

public class L20 {
    public boolean isValid(String s) {
        if (s == null || s.length() == 0) {
            return true;
        }
        if (s.length() % 2 != 0) {
            return false;
        }
        Stack<Character> s1 = new Stack<>();
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (c=='('||c=='['||c=='{'){
                s1.push(c);
            }else {
                if (s1.empty()==true){
                    return false;
                }
                Character pop = s1.pop();
                if ((pop=='('&& c!=')')||(pop=='['&& c!=']')||(pop=='{'&& c!='}')){
                    return false;
                }
            }

        }
        return s1.empty();


    }

}
